package com.ruoyi.web.controller.question;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.question.dto.QuestionDTO;
import com.ruoyi.question.service.IGenerateQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 题目管理Controller
 *
 * @author amy
 * @date 2025-06-11
 */
@RestController
@RequestMapping("/question/question")
@Tag(name = "【题目管理】管理")
public class GenerateQuestionController extends BaseController {

    @Autowired
    private IGenerateQuestionService generateQuestionService;

    /**
     * AI生成题目并插入数据库
     */
    @Operation(summary = "AI生成题目并写入数据库")
    @PreAuthorize("@ss.hasPermi('question:question:add')")
    @Log(title = "题目管理", businessType = BusinessType.INSERT)
    @PostMapping("/generateQuestions")
    public AjaxResult generateQuestionsAndInsert(@RequestBody QuestionDTO questionDTO) {
        questionDTO.setCreatedBy(getUsername());
        return generateQuestionService.generateAndInsertQuestions(questionDTO);
    }
}
